package main

import (
	"strconv"
	"strings"
)
func replace(num int, a byte) int {
	s := strconv.Itoa(num)
	i := 0
	for i < len(s) && s[i] == a {
		i++
	}
	if i < len(s) {
		t := s[i]
		s = strings.ReplaceAll(s, string(t), string(a))
		num, _ = strconv.Atoi(s)
	}
	return num
}
func minMaxDifference(num int) int {
    max_v := replace(num, '9')
	min_v := replace(num, '0')
	return max_v - min_v
}